package com.tangdi;

import java.io.File;
import java.io.FileInputStream;

import com.itextpdf.text.pdf.PdfReader;

public class UtilsPrintPDF {
	public static String printPDF(String[] filePaths){
		try{
        	for(int i = 0; i < filePaths.length; i++){
        		boolean isExist = checkFileExist(filePaths[i]);
        		if(isExist){
        			Runtime.getRuntime().exec("cmd.exe /C start acrord32 /P /h " + filePaths[i]);
        			}else{
	                	return "注意：" + filePaths[i] +" 文件不存在！";
	                }
        		PdfReader pdfReader = new PdfReader(new FileInputStream(filePaths[i]));
        		int pages = pdfReader.getNumberOfPages();
        		//System.out.println("pdf文件的总页数为:" + pages);
                
        		//Thread.sleep(2000 * pages);
        		if(i != (filePaths.length - 1)){
            		Thread.sleep(23000 * pages);	
        		}
        		
        	  }
	        }catch(Exception e){
				e.printStackTrace();
				return "打印过程出现异常！";
			}
		return "发送打印机成功！";
	}
	public static boolean checkFileExist(String filePath){
		File file = new File(filePath);
		if(!file.exists()){
		    return false;
		}
		return true;
	}

}
